﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SLBehaviourSystem
{
    [ActionComponent]
    public class MoveByPointsComponent : MoveComponent
    {
        public List<GameObject> Way;

        public int curIndex = 0;

        protected override void OnInit()
        {
            base.OnInit();
        }

        protected override void Move(float speed, float distanceOffset)
        {
            if (curIndex <= Way.Count - 1)
            {
                bool isEnd = MoveHelper.MoveToObj(gameObject, Way[curIndex], speed, distanceOffset, MoveType.CharacterController);
                if (isEnd)
                {
                    curIndex++;
                }
                OnExcuted(curIndex > Way.Count - 1 ? BehaviourNodeState.Success : BehaviourNodeState.Running);
            }
        }

        public override void Reset()
        {
            base.Reset();
            curIndex = 0;
        }
    }
}
